package com.gongpingjialoan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.bean.car.ChatCarBean;

import java.util.List;

/**
 * @Description:
 * @Author: chuang
 * @Since: 2016/9/2 13:51
 * @Version:
 */
public class PayCarListAdapter extends BaseAdapter {

    private List<ChatCarBean> mChatCarBean;

    private Context mContext;

    private LayoutInflater mLayoutInflater;
    private int selectPosition;

    public PayCarListAdapter(List<ChatCarBean> assessHistories, Context context) {
        mChatCarBean = assessHistories;
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
    }

    public void setData(List<ChatCarBean> mChatCarBean,int selectPosition) {
        this.mChatCarBean = mChatCarBean;
        this.selectPosition = selectPosition;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return mChatCarBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mChatCarBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.pay_car_item, null);
            holder = new ViewHolder();
            holder.checkImg = (ImageView) convertView.findViewById(R.id.check_img);
            holder.tvCarTitle = (TextView) convertView.findViewById(R.id.carName);
            convertView.setTag(R.id.tag_first, holder);
        } else {
            holder = (ViewHolder) convertView.getTag(R.id.tag_first);
        }
        ChatCarBean source = mChatCarBean.get(position);
        convertView.setTag(R.id.tag_second, source);
        if(source != null){
            holder.tvCarTitle.setText(source.title);
            if(selectPosition == position){
                holder.checkImg.setSelected(true);
            }else{
                holder.checkImg.setSelected(false);
            }
        }
        return convertView;
    }


    public static class ViewHolder {
        public ImageView checkImg;
        public TextView tvCarTitle;
    }
}

